﻿using System.IO.IsolatedStorage;

namespace GroupChallengeWP7.Models
{
    public class Player
    {
        private const string PlayerIdKey = "PlayerId";
        private const string NickNameKey = "NickName";
        private const string FullNameKey = "FullName";

        private int _playerId;
        private string _nickName;
        private string _fullName;

        public int PlayerId
        {
            get { return _playerId; }
            set { _playerId = value; }
        }

        public string NickName
        {
            get { return _nickName; }
            set { _nickName = value; }
        }

        public string FullName
        {
            get { return _fullName; }
            set { _fullName = value; }
        }

        // Save settings to isolated storage.
        public void SaveSettings(IsolatedStorageSettings settings)
        {
            // Add the setting if not already.
            if (!settings.Contains(PlayerIdKey))
                settings.Add(PlayerIdKey, string.Empty);

            if (!settings.Contains(NickNameKey))
                settings.Add(NickNameKey, string.Empty);

            if (!settings.Contains(FullNameKey))
                settings.Add(FullNameKey, string.Empty);

            settings[PlayerIdKey] = PlayerId;
            settings[NickNameKey] = _nickName;
            settings[FullNameKey] = _fullName;
        }

        // Load previous settings from isolated storage.
        public void LoadSettings(IsolatedStorageSettings settings)
        {
            settings.TryGetValue<int>(PlayerIdKey, out _playerId);
            settings.TryGetValue<string>(NickNameKey, out _nickName);
            settings.TryGetValue<string>(FullNameKey, out _fullName);
        }
    }
}
